package cn.weiron.fun.sample.controller;

import cn.weiron.fun.infrastructure.auth.Authority;
import cn.weiron.fun.infrastructure.dto.PageResult;
import cn.weiron.fun.sample.dto.RecordCountDto;
import cn.weiron.fun.sample.dto.RecordPageDto;
import cn.weiron.fun.sample.dto.SignRequestDto;
import cn.weiron.fun.sample.entity.SamplePointSign;
import cn.weiron.fun.sample.result.RecordCount;
import cn.weiron.fun.sample.result.SamplePointSignRecord;
import cn.weiron.fun.sample.service.SamplePointSignService;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * (SamplePointSign)表控制层
 *
 * @author makejava
 * @since 2022-07-16 10:36:19
 */
@RestController
@RequestMapping("/samplePointSign")
public class SamplePointSignController {

    public SamplePointSignController(@Qualifier("samplePointSignServiceImpl") SamplePointSignService samplePointSignService) {
        this.samplePointSignService = samplePointSignService;
    }

    /**
     * 服务对象
     */
    private final SamplePointSignService samplePointSignService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping
    @Authority.Set(mustLogin = false)
    public PageResult<SamplePointSign> queryByPage(SignRequestDto dto) {
        return samplePointSignService.queryByPage(dto);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<SamplePointSign> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.samplePointSignService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param samplePointSign 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<SamplePointSign> add(SamplePointSign samplePointSign) {
        return ResponseEntity.ok(this.samplePointSignService.insert(samplePointSign));
    }

    /**
     * 编辑数据
     *
     * @param samplePointSign 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<SamplePointSign> edit(SamplePointSign samplePointSign) {
        return ResponseEntity.ok(this.samplePointSignService.update(samplePointSign));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.samplePointSignService.deleteById(id));
    }

    /**
     * 季度打卡记录
     * @param dto 季度
     * @return
     */
    @GetMapping("/monthSign")
    @Authority.Set(mustLogin = false)
    public PageResult<SamplePointSignRecord> queryByYearAndMonth(@Validated RecordPageDto dto) {
        return samplePointSignService.queryByYearAndMonth(dto);
    }

    /**
     * 季度打卡统计d
     * @param dto
     * @return
     */
    @GetMapping("/count")
    @Authority.Set(mustLogin = false)
    public RecordCount queryCount(@Validated RecordCountDto dto) {
        return samplePointSignService.queryCount(dto);
    }


    /**
     * 操作日志
     * @param
     * @return
     */
    @GetMapping("/loginLog")
    @Authority.Set
    public void logRemark(HttpServletRequest request) {
         samplePointSignService.logRemark(request);
    }
}

